using System;
using Azure.Domain.Models;
using Microsoft.Security.Application;

namespace Azure.Web.Models
{
    public class CommentViewModel
    {
        public CommentViewModel()
        {
        }

        public CommentViewModel(Comment comment)
        {
            Body = AntiXss.HtmlEncode(comment.Body);
            Author = AntiXss.HtmlEncode(comment.Author);
            Created = comment.Timestamp;

            Uri website;
            if (Uri.TryCreate(comment.Website, UriKind.Absolute, out website))
            {
                Website = website;
            }
        }

        public string Body { get; set; }
        public Uri Website { get; set; }
        public string Author { get; set; }
        public DateTime Created { get; set; }
    }
}